package com.ly.mpayment.persist.service.zero;

import java.io.Serializable;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.ly.mpayment.persist.entity.ZeroBalance;
import com.ly.mpayment.persist.hibernate.Page;
import com.ly.mpayment.persist.service.AbstractService;

@Service
public class ZeroBalanceServiceImpl  extends AbstractService<ZeroBalance, Serializable> implements ZeroBalanceService {

	@Override
	public Page<ZeroBalance> pageZero(Map<String, Object> parameters, int start, int pageSize) {
		String hql = " select z from ZeroBalance z left join fetch z.user u where 1 = 1 " +
				"  #[and u.useruuid = :userId ]#  ";

		if(parameters.containsKey(":createtime")){
			hql += " and z.createTime >= '"+parameters.get(":createtime").toString()+"'";
			parameters.remove(":createtime");
		}
		if(parameters.containsKey(":endtime")){
			hql += " and z.createTime <= '"+parameters.get(":endtime").toString()+"'";
			parameters.remove(":endtime");
		}
		hql += "  order by z.createTime desc ";
		return this.findPageByNamed(hql, parameters, start, pageSize);
	}

	@Override
	public boolean saveZeroBalance(ZeroBalance zeroBalance) {
		if(zeroBalance != null){
			this.saveOrUpdate(zeroBalance);
			return true;
		}
		return false;
	}

}
